
  uint8_t data = 0;

void setup(){
  uint8_t x;
  Serial.begin(9600); 
  Serial.println("------------------------");
   pinMode(10,OUTPUT);//SS
  pinMode(11,OUTPUT);//MOSI
  pinMode(12,INPUT);//MISO
  pinMode(13,OUTPUT);//SCK
  SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0)|(1<<SPR1)|(1<<CPOL)|(1<<CPHA);

   x = SPSR;
  //Serial.println(x,HEX);//80
  x = SPDR;
  //x = 0x44;
  //Serial.println(x,HEX);//0
  x = SPSR;
  //Serial.println(x,HEX);//0
  //Serial.println(SPSR,HEX);//0
  Serial.println("start");
}
void spi_wait() {
  do {
    //Serial.print(SPSR,HEX);
  } 
  while (!(SPSR & (1 << SPIF)));
}
uint8_t spi_send(volatile uint8_t b) {
  uint8_t reply = 0xFF;
  //reply = SPSR;
  //Serial.println(reply,HEX);
  //reply = SPDR;
  SPDR = 0x23;
  //Serial.print("status =");
  //reply = SPSR;
  //Serial.println(reply,HEX);
   //
   
   //Serial.println(SPDR,HEX);
  spi_wait();
  reply = SPDR;
  Serial.print("balas = ");
  Serial.println(reply,HEX);
  return reply;
}

void loop(){

  spi_send(data);
  data++;
  //Serial.println(spi_send(0x40),HEX);
  delay(1000);
}


